/*
 * @Descripttion:
 * @Author: liujing
 * @Date: 2021-02-02 09:35:04
 * @LastEditTime: 2021-07-21 16:04:27
 */
import Vue from 'vue'

// 引入样式文件
import './style/index.less'

// 导入路由对象
import router from './router'

// 导入状态管理器
import store from './store'

import App from './pages/App'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI, { size: 'small', zIndex: 3000 })

// eslint-disable-next-line no-new
new Vue({
  el: '#app',
  router,
  store,
  render (ce) {
    return ce(App)
  }
})

Vue.config.productionTip = false

// 跳转到需要登录的页面需要进行用户登录认证，如果没有登录，需要跳转到登录页面
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    sessionStorage.removeItem('user')
  }
  var user = sessionStorage.getItem('user')
  if (!user && to.path !== '/login') {
    next({
      path: '/login'
    })
  } else {
    next()
  }
})
